package cn.com.yang.thread;

/**
 * ThreadLocal使用案例
 * TODO
 * @author yangyijin
 * @since 2023年12月15日-下午2:50:59
 */
public class TestThreadLocal {
	private static ThreadLocal<String> localVar = new ThreadLocal<String>();
	static void print(String str) {
		System.out.println(str+":"+localVar.get());
		localVar.remove();
	}
	public static void main(String[] args) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				TestThreadLocal.localVar.set("local_A");
				print("A");
				System.out.println("after remove :"+ localVar.get());
			}
		},"A").start();
		
		new Thread(new Runnable() {
			@Override
			public void run() {
				TestThreadLocal.localVar.set("local_B");
				print("A");
				System.out.println("after remove :"+ localVar.get());
			}
		},"B").start();
	}
}
